'use strict';

const Service = require('egg').Service;

class TestService extends Service {

  // 新增分类参数组
  async createSpecGroup(payload) {
    const { app } = this;
    return await app.model.MallSpecGroup.create(payload);
  }
  // 新增分类参数组
  async createSpecParam(payload) {
    const { app } = this;
    return await app.model.MallSpecParam.create(payload);
  }
  // 新增spu
  async createSpu(payload) {
    const { app } = this;
    return await app.model.MallSpu.create(payload);
  }
  // 新增SpuDetail
  async createSpuDetail(payload) {
    const { app } = this;
    return await app.model.MallSpuDetail.create(payload);
  }
  // 新增Sku
  async createSku(payload) {
    const { app } = this;
    return await app.model.MallSku.create(payload);
  }

  // getSku
  async getSku(payload) {
    const { app } = this;
    const { pageNum, pageSize } = payload;
    const { count, rows } = await app.model.MallSku.findAndCountAll({
      offset: (pageNum - 1) * pageSize,
      limit: pageSize * 1,
    });
    return {
      pageNum,
      pageSize,
      total: count,
      list: rows,
    };
  }

  // // 删除商品分类
  // async destroy(payload) {
  //   const { app } = this;
  //   return await app.model.MallCategory.destroy({ where: { id: payload.ids }, force: true });
  // }

  // 修改商品分类
  // async update(id, payload) {
  //   const { app } = this;
  //   return await app.model.MallCategory.update(payload, { where: { id } });
  // }

}

module.exports = TestService;
